mir, GL: Split GL context creation in two phases
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 12 Feb 2015 02:03:18 +0000 (03:03 +0100)
committerMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 12 Feb 2015 02:03:18 +0000 (03:03 +0100)
Move egl_context initialization in gdk_gl_context_realize

 • gdk_window_create_gl_context() creates a GdkGLContext
 • gdk_gl_context_realize() creates the underlying resources

https://bugzilla.gnome.org/show_bug.cgi?id=741946

gdk/mir/gdkmirglcontext.c
gdk/mir/gdkmirwindowimpl.c

index 8a7494be480c68737bd72b8627375339b417969f..5cacdb5786349ec8c59d1d1757dcddbc9248cf16 100644 (file)
 
 G_DEFINE_TYPE (GdkMirGLContext, gdk_mir_gl_context, GDK_TYPE_GL_CONTEXT)
 
+static gboolean
+gdk_mir_gl_context_realize (GdkGLContext *context,
+                            GError      **error)
+{
+  GdkMirGLContext *context_mir = GDK_MIR_GL_CONTEXT (context);
+  GdkDisplay *display = gdk_gl_context_get_display (context);
+  GdkGLContext *share = gdk_gl_context_get_shared_context (context);
+  GdkGLProfile profile = gdk_gl_context_get_profile (context);
+  EGLContext ctx;
+  EGLint context_attribs[3];
+  int i;
+
+  if (!_gdk_mir_display_init_egl_display (display))
+    {
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_NOT_AVAILABLE,
+                           _("No GL implementation is available"));
+      return FALSE;
+    }
+
+  i = 0;
+  if (profile == GDK_GL_PROFILE_3_2_CORE)
+    {
+      context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
+      context_attribs[i++] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
+    }
+  context_attribs[i++] = EGL_NONE;
+
+  ctx = eglCreateContext (_gdk_mir_display_get_egl_display (display),
+                          context_mir->egl_config,
+                          share != NULL ? GDK_MIR_GL_CONTEXT (share)->egl_context
+                                        : EGL_NO_CONTEXT,
+                          context_attribs);
+  if (ctx == NULL)
+    {
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_NOT_AVAILABLE,
+                           _("Unable to create a GL context"));
+      return FALSE;
+    }
+
+  GDK_NOTE (OPENGL, g_print ("Created EGL context[%p]\n", ctx));
+
+  context_mir->egl_context = ctx;
+
+  return TRUE;
+}
+
 static void
 gdk_mir_gl_context_end_frame (GdkGLContext *context,
                               cairo_region_t *painted,
@@ -96,6 +144,7 @@ gdk_mir_gl_context_class_init (GdkMirGLContextClass *klass)
   GdkGLContextClass *context_class = GDK_GL_CONTEXT_CLASS (klass);
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
+  context_class->realize = gdk_mir_gl_context_realize;
   context_class->end_frame = gdk_mir_gl_context_end_frame;
   gobject_class->dispose = gdk_mir_gl_context_dispose;
 }
index 1d560483b785fb95a664abac521d9c20e136309a..cddb55b68b67a17dc10716df05b7d6f3ec45ee05 100644 (file)
@@ -1398,10 +1398,7 @@ gdk_mir_window_impl_create_gl_context (GdkWindow     *window,
 {
   GdkDisplay *display = gdk_window_get_display (window);
   GdkMirGLContext *context;
-  EGLContext ctx;
   EGLConfig config;
-  int i;
-  EGLint context_attribs[3];
 
   if (!_gdk_mir_display_init_egl_display (display))
     {
@@ -1426,29 +1423,6 @@ gdk_mir_window_impl_create_gl_context (GdkWindow     *window,
   if (!find_eglconfig_for_window (window, &config, error))
     return NULL;
 
-  i = 0;
-  if (profile == GDK_GL_PROFILE_3_2_CORE)
-    {
-      context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
-      context_attribs[i++] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
-    }
-  context_attribs[i++] = EGL_NONE;
-
-  ctx = eglCreateContext (_gdk_mir_display_get_egl_display (display),
-                          config,
-                          share ? GDK_MIR_GL_CONTEXT (share)->egl_context : EGL_NO_CONTEXT,
-                          context_attribs);
-  if (ctx == NULL)
-    {
-      g_set_error_literal (error, GDK_GL_ERROR,
-                           GDK_GL_ERROR_NOT_AVAILABLE,
-                           _("Unable to create a GL context"));
-      return NULL;
-    }
-
-  GDK_NOTE (OPENGL,
-            g_print ("Created EGL context[%p]\n", ctx));
-
   context = g_object_new (GDK_TYPE_MIR_GL_CONTEXT,
                           "display", display,
                           "window", window,
@@ -1457,7 +1431,6 @@ gdk_mir_window_impl_create_gl_context (GdkWindow     *window,
                           NULL);
 
   context->egl_config = config;
-  context->egl_context = ctx;
   context->is_attached = attached;
 
   return GDK_GL_CONTEXT (context);